package com.jsyxdl.k3cloud.listener.handling;

import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.hustcad.plm.pdm.baseline.module.dto.TyplmBaseLineMemberObjParam;
import com.hustcad.plm.pdm.baseline.module.dto.TyplmBaseLineMemberParam;
import com.hustcad.plm.pdm.baseline.module.vo.TyplmBaseLineMemberVO;
import com.hustcad.plm.pdm.baseline.module.vo.TyplmBaseLineObjectVO;
import com.hustcad.plm.pdm.baseline.service.TyplmBaseLineMemberService;
import com.hustcad.plm.pdm.flowbusiness.model.entity.FlowObject;
import com.hustcad.plm.pdm.partbom.dto.ChildPartsFiltersDTO;
import com.hustcad.plm.pdm.partbom.dto.PartBomTree;
import com.hustcad.plm.pdm.partbom.dto.PartUsageLink;
import com.hustcad.plm.pdm.partbom.dto.QuerySubstituteLinkDTO;
import com.hustcad.plm.pdm.partbom.dto.TyplmUpdateLinkIbaDTO;
import com.hustcad.plm.pdm.partbom.service.TyplmPartBomService;
import com.hustcad.plm.pdm.partbom.service.partalternate.TyplmPdmPartAlternateService;
import com.hustcad.plm.pdm.partbom.service.partalternate.TyplmPdmPartSubstituteService;
import com.hustcad.plm.pdm.partbom.vo.AlternateInfoVO;
import com.hustcad.plm.pdm.partbom.vo.ParentPartDetailVO;
import com.hustcad.plm.pdm.partbom.vo.PartBomTreeByFilterVO;
import com.hustcad.plm.pdm.partbom.vo.PartDetailsVO;
import com.hustcad.plm.pdm.partbom.vo.PartSubstituteVO;
import com.jsyxdl.k3cloud.listener.K3CloudHttpService;
import com.jsyxdl.k3cloud.service.ErpWorkedTaskService;
import com.jsyxdl.k3cloud.service.WorkedTaskService;
import com.jsyxdl.k3cloud.utils.HttpMethodEnum;
import com.jsyxdl.k3cloud.utils.PlmPartOptionUtils;
import com.jsyxdl.k3cloud.utils.SendErpDataUtils;
import com.jsyxdl.service.ErpK3cloudService;
import com.jsyxdl.service.ErpPartAlternativeService;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.org.UserDO;
import com.ty.basic.exception.message.SystemErrorCodeEnum;
import com.ty.basic.session.TyAccountContext;
import org.apache.commons.lang3.ObjectUtils;

import java.math.BigInteger;
import java.sql.Connection;
import java.util.*;

/**
 * 物料清单创建处理服务
 */
public class BuildBomHandling implements ErpWorkedTaskService {

    /***
     * 供发布流程调用
     * @param executionType
     * @param flowObject
     * @return
     * @throws Exception
     */
    @Override
    public JSONObject productionCall(Map<String, Object> executionType, FlowObject flowObject) throws Exception {

        K3CloudHttpService k3CloudHttpService = SpringUtil.getBean(K3CloudHttpService.class);
        PlmPartOptionUtils plmPartOptionUtils = SpringUtil.getBean(PlmPartOptionUtils.class);
        TyplmPdmPartAlternateService typlmPartAlternateService = SpringUtil.getBean(TyplmPdmPartAlternateService.class);
        TyplmPdmPartSubstituteService typlmPartSubstituteService = SpringUtil.getBean(
                TyplmPdmPartSubstituteService.class);
        ErpK3cloudService erpK3cloudService = SpringUtil.getBean(ErpK3cloudService.class);

        UserDO userDO = TyAccountContext.getUser();
        String k3cloud = (String) executionType.get("k3cloud");
        String code = (String) executionType.get("code");

        TyplmPartBomService typlmPartBomService = SpringUtil.getBean(TyplmPartBomService.class);
        if (typlmPartBomService != null) {
            BigInteger coid = flowObject.getRefObjectOid();
            String coType = flowObject.getRefObjectOtype();
            PartDetailsVO partDetails = plmPartOptionUtils.getPartDetailsVO(coid, coType);

            Map<String,Object> groupType=new HashMap<>();
            groupType.putAll(executionType);

            com.hustcad.plm.pdm.partbom.dto.ExpandBomTreeByFilterDTO expandBomTreeByFilterDTO = new com.hustcad.plm.pdm.partbom.dto.ExpandBomTreeByFilterDTO();
            expandBomTreeByFilterDTO.setAttrFilterCondition(new ArrayList<>());

            ChildPartsFiltersDTO childPartsFiltersDTO = new ChildPartsFiltersDTO();
            childPartsFiltersDTO.setBaseLineOid("");
            childPartsFiltersDTO.setDate("");
            childPartsFiltersDTO.setExpandCondition("latest");
            childPartsFiltersDTO.setLifecycleStateKey("");
            childPartsFiltersDTO.setPurposeOfBom("");
            childPartsFiltersDTO.setSpareBom("");
            childPartsFiltersDTO.setView(partDetails.getView());
            List<ChildPartsFiltersDTO> list = new ArrayList<>();
            list.add(childPartsFiltersDTO);
            expandBomTreeByFilterDTO.setConditions(list);

            expandBomTreeByFilterDTO.setExpandLevel("N");
            expandBomTreeByFilterDTO.setFatherNumber(partDetails.getObjectNumber());
            expandBomTreeByFilterDTO.setFatherOid(String.valueOf(partDetails.getOid()));
            expandBomTreeByFilterDTO.setFatherOtype(partDetails.getOtype());
            expandBomTreeByFilterDTO.setFilterMode("0");
            expandBomTreeByFilterDTO.setGiveUsesOccurrence("N");
            expandBomTreeByFilterDTO.setIbaColumns(new ArrayList<>());
            expandBomTreeByFilterDTO.setIsApplyRoot(false);
            expandBomTreeByFilterDTO.setIsFilterAttr(false);
            expandBomTreeByFilterDTO.setIsNeedTranEnum(true);
            expandBomTreeByFilterDTO.setIsNestedTree(true);
            expandBomTreeByFilterDTO.setIsQueryIBA(true);

            PartBomTreeByFilterVO result = typlmPartBomService.expandBomTreeByFilterNew(expandBomTreeByFilterDTO,
                                                                                        Boolean.TRUE);
            Set<PartBomTree> set = new LinkedHashSet<>();

            for (int i = 0; i < result.getPartBomTreeList().size(); i++) {
                set.add(result.getPartBomTreeList().get(i));
            }
            List<PartBomTree> bomTreeList = new LinkedList<>();
            List<PartBomTree> dgBomTreeList = new LinkedList<>();
            k3CloudHttpService.getRecursionBom(set, dgBomTreeList);

            int level =0;
            for (int i = 0; i < dgBomTreeList.size(); i++) {
                int entityLevel=Integer.parseInt(dgBomTreeList.get(i).getLevel());
                if(entityLevel>level){
                    level=entityLevel;
                }
            }

            //排序创建顺序
            for(int d=level;d>-1;d--){
                for(int i=0;i<dgBomTreeList.size();i++){
                    int entityLevel=Integer.parseInt(dgBomTreeList.get(i).getLevel());
                    if(d==entityLevel){
                        bomTreeList.add(dgBomTreeList.get(i));
                    }
                }
            }

            List<Map<String, Object>> options = k3CloudHttpService.getOptions(code, k3cloud);
            Map<String, Object> inMap = k3CloudHttpService.getInTreeMap(code, k3cloud);

            //循环发送ERP构建层级物料清单BOM
            //移除相同的BOM
            Map<String, Object> partMap = new HashMap<>();
            List<String> erpNumbers = new ArrayList<>();
            Map<String, String> bomVersion = new HashMap<>();

            String groupNumber = null;
            groupNumber = createGroup(partDetails, groupType);
            if (groupNumber == null) {
                throw SystemErrorCodeEnum.WORK_FLOW_CONTENT_ERROR.getException(
                        partDetails.getIdentifierDisplayName() + "的扩展属性【图纸号】或【型号】必填，否则ERP中无法创建物料分组");
            }

            for (int a = 0; a < bomTreeList.size(); a++) {
                PartBomTree partBomTree = bomTreeList.get(a);
                if (partMap.containsKey(partBomTree.getObjectNumber())) {
                    bomTreeList.remove(a);
                    a--;
                    continue;
                } else {
                    partMap.put(partBomTree.getObjectNumber(), partBomTree);
                }

                Map<String, Object> bomKeyValue = new HashMap<>();
                BigInteger partOid = new BigInteger(partBomTree.getPartoid());
                String partType = partBomTree.getPartotype();
                PartDetailsVO parentDetailsVO = plmPartOptionUtils.getPartDetailsVO(partOid, partType);

                Map<String, PartBomTree> childPartBomTreeMap = new HashMap<>();
                if (partBomTree.getChildren().size() > 0) {
                    JSONObject partJson = JSONObject.parseObject(JSONObject.toJSONString(parentDetailsVO));
                    List<Map<String, Object>> baseCodeList = erpK3cloudService.getBaseCode(partDetails.getClassId());

                    if (baseCodeList != null && baseCodeList.size() > 0) {
                        partJson.put("baseClassificationCode", baseCodeList.get(0).get("objectnumber"));
                    }
                    Map<String, Object> partKey = new HashMap<>();
                    for (Map<String, Object> option : options) {
                        if ("类型属性".equals(option.get("plmtype"))) {
                            k3CloudHttpService.setInTree(
                                    (List<Map<String, Object>>) inMap.get(option.get("plm_source_type_id")), partJson,
                                    partKey);
                            break;
                        }
                    }
                    bomKeyValue.putAll(partKey);

                    for (PartBomTree childPartBomTree : partBomTree.getChildren()) {
                        childPartBomTreeMap.put(childPartBomTree.getObjectNumber(), childPartBomTree);
                        BigInteger cpartOid = new BigInteger(childPartBomTree.getPartoid());
                        String cpartType = childPartBomTree.getPartotype();
                        PartDetailsVO partDetailsVO = plmPartOptionUtils.getPartDetailsVO(cpartOid, cpartType);


                        JSONObject childPartJson = JSONObject.parseObject(JSONObject.toJSONString(partDetailsVO));

                        List<Map<String, Object>> cbaseCodeList = erpK3cloudService.getBaseCode(
                                partDetails.getClassId());
                        if (cbaseCodeList != null && cbaseCodeList.size() > 0) {
                            partJson.put("baseClassificationCode", cbaseCodeList.get(0).get("objectnumber"));
                        }


                        Map<String, Object> partKeyValue = new HashMap<>();
                        for (Map<String, Object> option : options) {
                            if ("类型属性".equals(option.get("plmtype"))) {
                                k3CloudHttpService.setInTree(
                                        (List<Map<String, Object>>) inMap.get(option.get("plm_source_type_id")),
                                        childPartJson, partKeyValue);
                                break;
                            }
                        }

                        BigInteger oid = childPartBomTree.getOid();
                        String oType = childPartBomTree.getOtype();
                        PartUsageLink partUsageLink = plmPartOptionUtils.getPartUsageLink(oid, oType);

                        JSONObject voJson = JSONObject.parseObject(JSONObject.toJSONString(partUsageLink));
                        Map<String, Object> voJsonMap = voJson.getInnerMap();

                        Map<String, Object> listKeyValue = new HashMap<>();
                        String plm_source_type_id = null;
                        for (Map<String, Object> option : options) {
                            if ("BOM属性".equals(option.get("plmtype"))) {
                                plm_source_type_id = (String) option.get("plm_source_type_id");
                                k3CloudHttpService.setInTree((List<Map<String, Object>>) inMap.get(plm_source_type_id),
                                                             voJsonMap, listKeyValue);
                                break;
                            }
                        }
                        listKeyValue.putAll(partKeyValue);


                        if (bomKeyValue.containsKey(plm_source_type_id)) {
                            List<Map<String, Object>> bomList = (List<Map<String, Object>>) bomKeyValue.get(
                                    plm_source_type_id);
                            bomList.add(listKeyValue);
                        } else {
                            List<Map<String, Object>> bomList = new ArrayList<>();
                            bomList.add(listKeyValue);
                            bomKeyValue.put(plm_source_type_id, bomList);
                        }

                    }
                }

                executionType.put("plm_code",parentDetailsVO.getIdentifierDisplayName());


                Map<String, Object> out = k3CloudHttpService.plmToK3CloudOut(code, k3cloud, new HashMap<>(),
                                                                             bomKeyValue);


                List<String> AlternativeNumbers = new ArrayList<>();
                List<Map<String, Object>> fzList = new ArrayList<>();

                //处理替代件逻辑
                if (out.containsKey("Model")) {
                    Map<String, Object> Model = (Map<String, Object>) out.get("Model");
                    String bomV=String.format("%s-%s",parentDetailsVO.getObjectNumber(),parentDetailsVO.getDisplayVersion());
                    Model.put("FNumber",bomV);
                    bomVersion.put(parentDetailsVO.getObjectNumber(),bomV);
                    if (Model.containsKey("FTreeEntity")) {
                        List<Map<String, Object>> FTreeEntity = (List<Map<String, Object>>) Model.get("FTreeEntity");

                        for (int x = 0; x < FTreeEntity.size(); x++) {
                            //添加基线描述
                            //FTreeEntity.get(x).put("F_SDTD_BOMJXBB ", baseLineDescription);

                            Map<String, Object> FMATERIALIDCHILD = (Map<String, Object>) FTreeEntity.get(x).get(
                                    "FMATERIALIDCHILD");
                            String FNumber = (String) FMATERIALIDCHILD.get("FNumber");


                            if(bomVersion.containsKey(FNumber)){
                                Map<String,String> FBOMID=new HashMap<>();
                                FBOMID.put("FNumber",bomVersion.get(FNumber));
                                FTreeEntity.get(x).put("FBOMID", FBOMID);
                            }

                            if (childPartBomTreeMap.containsKey(FNumber)) {
                                PartBomTree childPartBomTree = childPartBomTreeMap.get(FNumber);
                                List<String> alternateForPartNumbers = new ArrayList<>();
                                alternateForPartNumbers.add(childPartBomTree.getObjectNumber());


                                //查询局部替代件
                                QuerySubstituteLinkDTO querySubstituteLinkDTO = new QuerySubstituteLinkDTO();
                                if (ObjectUtils.isNotEmpty(userDO) && ObjectUtils.isNotEmpty(userDO.getOid())) {
                                    querySubstituteLinkDTO.setUserOid(userDO.getOid());
                                }
                                querySubstituteLinkDTO.setAoid(String.valueOf(childPartBomTree.getAoid()));
                                querySubstituteLinkDTO.setBnumber(String.valueOf(childPartBomTree.getObjectNumber()));
                                querySubstituteLinkDTO.setBoid(String.valueOf(childPartBomTree.getPartoid()));
                                List<PartSubstituteVO> listSubstitute = typlmPartSubstituteService.queryPartSubstituteLink(
                                        querySubstituteLinkDTO);


                                if (listSubstitute != null && listSubstitute.size() > 0) {
                                    AlternativeNumbers.add(childPartBomTree.getObjectNumber());
                                    List<String> aNumbers = new ArrayList<>();
                                    aNumbers.add(childPartBomTree.getObjectNumber());
                                    for (int s = 0; s < listSubstitute.size(); s++) {
                                        PartSubstituteVO partSubstituteVO = listSubstitute.get(s);
                                        String plmFSubstitutionId = null;
                                        Map<String, List<String>> baAttributeMap = partSubstituteVO.getIbaAttributeMap();
                                        if (baAttributeMap != null) {
                                            if (baAttributeMap.containsKey("替代方案编码")) {
                                                List<String> cList = baAttributeMap.get("替代方案编码");
                                                if (cList.size() > 0 && "".equals(cList.get(0)) == false) {
                                                    plmFSubstitutionId = cList.get(0);
                                                }
                                            }
                                        }
                                        Map<String, Object> fz = clone(FTreeEntity.get(x));
                                        //项次
                                        fz.put("FReplaceGroup", x + 1);
                                        FTreeEntity.get(x).put("FReplaceGroup", x + 1);

                                        //子件类型： 1 标准件， 2 返还件，3 替代件
                                        fz.put("FMATERIALTYPE", "3");


                                        fz.put("FIskeyItem", true);
                                        FTreeEntity.get(x).put("FIskeyItem", true);


                                        //替代策略： 手工替代，内部值 3
                                        fz.put("FReplacePolicy", "3");
                                        FTreeEntity.get(x).put("FReplacePolicy", "3");


                                        //替代优先级
                                        fz.put("FReplacePriority", s + 1);
                                        //FTreeEntity.get(x).put("FReplacePriority",1);


                                        //动态优先级
                                        fz.put("FMRPPriority", s + 1);


                                        Map<String, String> FSubstitutionId = new HashMap<>();
                                        FSubstitutionId.put("FNUMBER", (String) plmFSubstitutionId);
                                        //替代方案编码
                                        fz.put("FSubstitutionId", FSubstitutionId);

                                        Map<String, String> FSubstitutionId1 = new HashMap<>();
                                        FSubstitutionId1.put("FNUMBER", (String) plmFSubstitutionId);
                                        FTreeEntity.get(x).put("FSubstitutionId", FSubstitutionId1);

                                        //替代方式： 1=替代，2=取代
                                        fz.put("FReplaceType", "1");
                                        FTreeEntity.get(x).put("FReplaceType", "1");

                                        Map<String, String> tdFMATERIALIDCHILD = new HashMap<>();
                                        tdFMATERIALIDCHILD.put("FNumber",
                                                               new String(listSubstitute.get(s).getNumber()));
                                        //子项物料编码
                                        fz.put("FMATERIALIDCHILD", tdFMATERIALIDCHILD);

                                        fzList.add(fz);
                                    }
                                } else {
                                    FTreeEntity.get(x).put("FReplaceGroup", x + 1);
                                }
                                //查询全局替代件
                                List<AlternateInfoVO> listAlternates = typlmPartAlternateService.batchQueryAlternates(
                                        alternateForPartNumbers);
                                if (listAlternates != null && listAlternates.size() > 0) {
                                    AlternativeNumbers.add(childPartBomTree.getObjectNumber());

                                    if (listSubstitute.size() > 0) {
                                        continue;
                                    }
                                    List<String> aNumbers = new ArrayList<>();
                                    aNumbers.add(childPartBomTree.getObjectNumber());

                                    for (int s = 0; s < listAlternates.size(); s++) {
                                        AlternateInfoVO alternateInfoVO = listAlternates.get(s);

                                        String plmFSubstitutionId = null;
                                        Map<String, List<String>> baAttributeMap = alternateInfoVO.getIbaAttributeMap();
                                        if (baAttributeMap != null) {
                                            if (baAttributeMap.containsKey("替代方案编码")) {
                                                List<String> cList = baAttributeMap.get("替代方案编码");
                                                if (cList.size() > 0 && "".equals(cList.get(0)) == false) {
                                                    plmFSubstitutionId = cList.get(0);
                                                }
                                            }
                                        }


                                        Map<String, Object> fz = clone(FTreeEntity.get(x));
                                        //项次
                                        fz.put("FReplaceGroup", x + 1);
                                        FTreeEntity.get(x).put("FReplaceGroup", x + 1);


                                        //替代主料
                                        fz.put("FIskeyItem", true);
                                        FTreeEntity.get(x).put("FIskeyItem", true);

                                        // 子项类型
                                        fz.put("FMATERIALTYPE", "3");

                                        //替代策略： 手工替代，内部值 3
                                        fz.put("FReplacePolicy", "3");
                                        FTreeEntity.get(x).put("FReplacePolicy", "3");


                                        //替代优先级
                                        fz.put("FReplacePriority", s + 1);
                                        //FTreeEntity.get(x).put("FReplacePriority",1);

                                        //动态优先级
                                        fz.put("FMRPPriority", s + 1);


                                        Map<String, String> FSubstitutionId = new HashMap<>();
                                        FSubstitutionId.put("FNUMBER", (String) plmFSubstitutionId);
                                        //替代方案编码
                                        fz.put("FSubstitutionId", FSubstitutionId);

                                        Map<String, String> FSubstitutionId1 = new HashMap<>();
                                        FSubstitutionId1.put("FNUMBER", (String) plmFSubstitutionId);
                                        FTreeEntity.get(x).put("FSubstitutionId", FSubstitutionId1);

                                        //替代方式： 1=替代，2=取代
                                        fz.put("FReplaceType", "2");
                                        FTreeEntity.get(x).put("FReplaceType", "2");

                                        Map<String, String> tdFMATERIALIDCHILD = new HashMap<>();
                                        tdFMATERIALIDCHILD.put("FNumber", new String(
                                                listAlternates.get(s).getAlternateObjectNumber()));
                                        //子项物料编码
                                        fz.put("FMATERIALIDCHILD", tdFMATERIALIDCHILD);

                                        fzList.add(fz);
                                    }
                                } else {
                                    FTreeEntity.get(x).put("FReplaceGroup", x + 1);
                                }

                            }
                        }
                    }

                    if(Model.containsKey("FGroup")){
                        Map<String,Object> FGroup= (Map<String, Object>) Model.get("FGroup");
                        FGroup.put("FNumber",groupNumber);
                    }
                }


                //排序数据
                if (AlternativeNumbers.size() > 0) {
                    Map<Integer, List<Map<String, Object>>> pxMap = new HashMap<>();
                    if (out.containsKey("Model")) {
                        Map<String, Object> Model = (Map<String, Object>) out.get("Model");
                        if (Model.containsKey("FTreeEntity")) {
                            List<Map<String, Object>> FTreeEntity = (List<Map<String, Object>>) Model.get(
                                    "FTreeEntity");
                            List<Map<String, Object>> srcList = new ArrayList<>();
                            for (int x = 0; x < FTreeEntity.size(); x++) {
                                Integer FReplaceGroup = (Integer) FTreeEntity.get(x).get("FReplaceGroup");
                                if (FReplaceGroup != null) {
                                    if (pxMap.containsKey(FReplaceGroup)) {
                                        List<Map<String, Object>> xlist = pxMap.get(FReplaceGroup);
                                        xlist.add(FTreeEntity.get(x));
                                        for (int v = 0; v < fzList.size(); v++) {
                                            Integer fzeplaceGroup = (Integer) fzList.get(v).get("FReplaceGroup");
                                            if (fzeplaceGroup == FReplaceGroup) {
                                                xlist.add(fzList.get(v));
                                            }
                                        }
                                    } else {
                                        List<Map<String, Object>> xlist = new ArrayList<>();
                                        xlist.add(FTreeEntity.get(x));
                                        for (int v = 0; v < fzList.size(); v++) {
                                            Integer fzeplaceGroup = (Integer) fzList.get(v).get("FReplaceGroup");
                                            if (fzeplaceGroup == FReplaceGroup) {
                                                xlist.add(fzList.get(v));
                                            }

                                        }
                                        pxMap.put(FReplaceGroup, xlist);
                                    }


                                } else {
                                    srcList.add(FTreeEntity.get(x));
                                }

                            }
                            List<Map<String, Object>> stroList = new ArrayList<>();
                            for (Integer i = 0; i < FTreeEntity.size() + 1; i++) {
                                if (pxMap.containsKey(i)) {
                                    List<Map<String, Object>> xlist = pxMap.get(i);
                                    for (int v = 0; v < xlist.size(); v++) {
                                        stroList.add(xlist.get(v));
                                    }
                                }
                            }

                            for (int i = 0; i < srcList.size(); i++) {
                                stroList.add(srcList.get(i));
                            }


                            Model.put("FTreeEntity", stroList);
                        }
                    }
                }

                JSONObject resultJson = SendErpDataUtils.sendErpDataTaskWorkder(executionType, out);


                JSONObject Result = resultJson.getJSONObject("Result");
                if (Result != null) {
                    JSONObject ResponseStatus = Result.getJSONObject("ResponseStatus");
                    if (ResponseStatus.getBooleanValue("IsSuccess") == false) {
                        throw SystemErrorCodeEnum.WORK_FLOW_CONTENT_ERROR.getException(
                                ResponseStatus.get("Errors").toString());
                    } else {
                        JSONArray successEntitys = ResponseStatus.getJSONArray("SuccessEntitys");
                        if (successEntitys.size() > 0) {
                            String erpNumber = successEntitys.getJSONObject(0).getString("Id");
                            if(erpNumber!=null && "null".equals(erpNumber)==false){
                                erpNumbers.add(erpNumber);
                            }
                        }
                    }
                }
            }

            if (erpNumbers.size() == 0) {
                JSONObject httpResult = new JSONObject();
                JSONObject resultObj = new JSONObject();
                JSONObject responseStatus = new JSONObject();
                responseStatus.put("IsSuccess", true);
                responseStatus.put("msg", "数据为空");
                resultObj.put("ResponseStatus", responseStatus);
                httpResult.put("Result", resultObj);
                return httpResult;
            }
            //构建批量提交数据，发送ERP提交BOM


            executionType.put("code","TJ000006X");
            JSONObject resultJson = SubmissionAndReviewHanding.submittReviewByIds(executionType, erpNumbers);
            JSONObject Result = resultJson.getJSONObject("Result");
            if (Result != null) {
                JSONObject ResponseStatus = Result.getJSONObject("ResponseStatus");
                if (ResponseStatus.getBooleanValue("IsSuccess") == false) {
                    throw SystemErrorCodeEnum.WORK_FLOW_CONTENT_ERROR.getException(
                            ResponseStatus.get("Errors").toString());
                }
            }
            return resultJson;
        }

        return null;
    }

    /***
     * 供变更流程调用
     * @param executionType
     * @param dgBomTreeList
     * @param baseLineMap
     * @return
     * @throws Exception
     */
    public JSONObject productionCall(Map<String, Object> executionType, List<PartBomTree> dgBomTreeList,Map<String, String> baseLineMap)
            throws Exception {

        K3CloudHttpService k3CloudHttpService = SpringUtil.getBean(K3CloudHttpService.class);
        PlmPartOptionUtils plmPartOptionUtils = SpringUtil.getBean(PlmPartOptionUtils.class);
        ErpK3cloudService erpK3cloudService = SpringUtil.getBean(ErpK3cloudService.class);
        TyplmPartBomService typlmPartBomService = SpringUtil.getBean(TyplmPartBomService.class);
        TyplmPdmPartAlternateService typlmPartAlternateService = SpringUtil.getBean(TyplmPdmPartAlternateService.class);
        TyplmPdmPartSubstituteService typlmPartSubstituteService = SpringUtil.getBean(TyplmPdmPartSubstituteService.class);


        String k3cloud = (String) executionType.get("k3cloud");
        String code = (String) executionType.get("code");

        UserDO userDO = TyAccountContext.getUser();

        if (typlmPartBomService != null) {

            List<Map<String, Object>> options = k3CloudHttpService.getOptions(code, k3cloud);

            Map<String, Object> inMap = k3CloudHttpService.getInTreeMap(code, k3cloud);

            //循环发送ERP构建层级物料清单BOM
            //移除相同的BOM
            Map<String, Object> partMap = new HashMap<>();
            List<PartBomTree> afterStatus = new ArrayList<>();

            List<String> erpNumbers = new ArrayList<>();

            List<PartBomTree> bomTreeList = new LinkedList<>();

            int level =0;
            for (int i = 0; i < dgBomTreeList.size(); i++) {
                int entityLevel=Integer.parseInt(dgBomTreeList.get(i).getLevel());
                if(entityLevel>level){
                    level=entityLevel;
                }
            }
            //排序创建顺序
            for(int d=level;d>-1;d--){
                for(int i=0;i<dgBomTreeList.size();i++){
                    int entityLevel=Integer.parseInt(dgBomTreeList.get(i).getLevel());
                    if(d==entityLevel){
                        bomTreeList.add(dgBomTreeList.get(i));
                    }
                }
            }
            Map<String,String> bomVersion=new HashMap<>();

            PartBomTree parentBomTree=null;
            for (int i = 0; i < dgBomTreeList.size(); i++) {
                int entityLevel=Integer.parseInt(dgBomTreeList.get(i).getLevel());
                if(entityLevel==0){
                    parentBomTree=dgBomTreeList.get(i);
                }
            }

            if(parentBomTree==null){
                throw SystemErrorCodeEnum.WORK_FLOW_CONTENT_ERROR.getException("查不到父项BOM数据");
            }

            BigInteger sOid = new BigInteger(parentBomTree.getPartoid());
            String sType = parentBomTree.getPartotype();
            PartDetailsVO parentDetails = plmPartOptionUtils.getPartDetailsVO(sOid, sType);

            Map<String,Object> groupType=new HashMap<>();
            groupType.putAll(executionType);

            String groupNumber=null;



            for (int a = 0; a < bomTreeList.size(); a++) {
                PartBomTree partBomTree = bomTreeList.get(a);
                if (partMap.containsKey(partBomTree.getObjectNumber())) {
                    bomTreeList.remove(a);
                    a--;
                    continue;
                } else {
                    partMap.put(partBomTree.getObjectNumber(), partBomTree);
                }

                Map<String, Object> bomKeyValue = new HashMap<>();
                BigInteger partOid = new BigInteger(partBomTree.getPartoid());
                String partType = partBomTree.getPartotype();
                PartDetailsVO parentDetailsVO = plmPartOptionUtils.getPartDetailsVO(partOid, partType);

                Map<String, PartBomTree> childPartBomTreeMap = new HashMap<>();
                if (partBomTree.getChildren().size() > 0) {

                    groupNumber=createGroup(parentDetails,groupType);
                    if(groupNumber==null){
                        throw SystemErrorCodeEnum.WORK_FLOW_CONTENT_ERROR.getException("零部件图纸号必填");
                    }

                    executionType.put("plm_code",parentDetailsVO.getIdentifierDisplayName());

                    afterStatus.add(partBomTree);


                    JSONObject partJson = JSONObject.parseObject(JSONObject.toJSONString(parentDetailsVO));

                    List<Map<String, Object>> baseCodeList = erpK3cloudService.getBaseCode(
                            partBomTree.getClassficationOid());
                    if (baseCodeList != null && baseCodeList.size() > 0) {
                        partJson.put("baseClassificationCode", baseCodeList.get(0).get("objectnumber"));
                    }

                    Map<String, Object> partKey = new HashMap<>();
                    for (Map<String, Object> option : options) {
                        if ("类型属性".equals(option.get("plmtype"))) {
                            k3CloudHttpService.setInTree(
                                    (List<Map<String, Object>>) inMap.get(option.get("plm_source_type_id")), partJson,
                                    partKey);
                            break;
                        }
                    }
                    bomKeyValue.putAll(partKey);

                    for (PartBomTree childPartBomTree : partBomTree.getChildren()) {
                        childPartBomTreeMap.put(childPartBomTree.getObjectNumber(), childPartBomTree);

                        BigInteger cpartOid = new BigInteger(childPartBomTree.getPartoid());
                        String cpartType = childPartBomTree.getPartotype();
                        PartDetailsVO partDetailsVO = plmPartOptionUtils.getPartDetailsVO(cpartOid, cpartType);

                        JSONObject childPartJson = JSONObject.parseObject(JSONObject.toJSONString(partDetailsVO));

                        List<Map<String, Object>> cbaseCodeList = erpK3cloudService.getBaseCode(
                                childPartBomTree.getClassficationOid());
                        if (cbaseCodeList != null && cbaseCodeList.size() > 0) {
                            partJson.put("baseClassificationCode", cbaseCodeList.get(0).get("objectnumber"));
                        }


                        Map<String, Object> partKeyValue = new HashMap<>();
                        for (Map<String, Object> option : options) {
                            if ("类型属性".equals(option.get("plmtype"))) {
                                k3CloudHttpService.setInTree(
                                        (List<Map<String, Object>>) inMap.get(option.get("plm_source_type_id")),
                                        childPartJson, partKeyValue);
                                break;
                            }
                        }

                        BigInteger oid = childPartBomTree.getOid();
                        String oType = childPartBomTree.getOtype();
                        PartUsageLink partUsageLink = plmPartOptionUtils.getPartUsageLink(oid, oType);

                        JSONObject voJson = JSONObject.parseObject(JSONObject.toJSONString(partUsageLink));
                        Map<String, Object> voJsonMap = voJson.getInnerMap();

                        Map<String, Object> listKeyValue = new HashMap<>();
                        String plm_source_type_id = null;
                        for (Map<String, Object> option : options) {
                            if ("BOM属性".equals(option.get("plmtype"))) {
                                plm_source_type_id = (String) option.get("plm_source_type_id");
                                k3CloudHttpService.setInTree((List<Map<String, Object>>) inMap.get(plm_source_type_id),
                                                             voJsonMap, listKeyValue);
                                break;
                            }
                        }
                        listKeyValue.putAll(partKeyValue);


                        if (bomKeyValue.containsKey(plm_source_type_id)) {
                            List<Map<String, Object>> bomList = (List<Map<String, Object>>) bomKeyValue.get(
                                    plm_source_type_id);
                            bomList.add(listKeyValue);
                        } else {
                            List<Map<String, Object>> bomList = new ArrayList<>();
                            bomList.add(listKeyValue);
                            bomKeyValue.put(plm_source_type_id, bomList);
                        }

                    }
                }


                Map<String, Object> out = k3CloudHttpService.plmToK3CloudOut(code, k3cloud, new HashMap<>(),
                                                                             bomKeyValue);


                List<String> AlternativeNumbers = new ArrayList<>();
                List<Map<String, Object>> fzList = new ArrayList<>();
                //处理替代件逻辑
                if (out.containsKey("Model")) {
                    Map<String, Object> Model = (Map<String, Object>) out.get("Model");
                    Map<String,Object> FMATERIALID= (Map<String, Object>) Model.get("FMATERIALID");
                    String bomV=String.format("%s-%s",parentDetailsVO.getObjectNumber(),parentDetailsVO.getDisplayVersion());
                    Model.put("FNumber",bomV);
                    bomVersion.put(parentDetailsVO.getObjectNumber(),bomV);

                    if (Model.containsKey("FTreeEntity")) {
                        List<Map<String, Object>> FTreeEntity = (List<Map<String, Object>>) Model.get("FTreeEntity");

                        for (int x = 0; x < FTreeEntity.size(); x++) {

                            Map<String, Object> FMATERIALIDCHILD = (Map<String, Object>) FTreeEntity.get(x).get(
                                    "FMATERIALIDCHILD");
                            String FNumber = (String) FMATERIALIDCHILD.get("FNumber");

                            if(bomVersion.containsKey(FNumber)){
                                Map<String,String> FBOMID=new HashMap<>();
                                FBOMID.put("FNumber",bomVersion.get(FNumber));
                                FTreeEntity.get(x).put("FBOMID", FBOMID);
                            }


                            if (childPartBomTreeMap.containsKey(FNumber)) {
                                PartBomTree childPartBomTree = childPartBomTreeMap.get(FNumber);
                                List<String> alternateForPartNumbers = new ArrayList<>();
                                alternateForPartNumbers.add(childPartBomTree.getObjectNumber());


                                //查询局部替代件
                                QuerySubstituteLinkDTO querySubstituteLinkDTO = new QuerySubstituteLinkDTO();
                                if (ObjectUtils.isNotEmpty(userDO) && ObjectUtils.isNotEmpty(userDO.getOid())) {
                                    querySubstituteLinkDTO.setUserOid(userDO.getOid());
                                }
                                querySubstituteLinkDTO.setAoid(String.valueOf(childPartBomTree.getAoid()));
                                querySubstituteLinkDTO.setBnumber(String.valueOf(childPartBomTree.getObjectNumber()));
                                querySubstituteLinkDTO.setBoid(String.valueOf(childPartBomTree.getPartoid()));
                                List<PartSubstituteVO> listSubstitute = typlmPartSubstituteService.queryPartSubstituteLink(
                                        querySubstituteLinkDTO);


                                //移除旧版本的替代关系
                                if (listSubstitute.size() > 0) {
                                    for (int y = 0; y < listSubstitute.size(); y++) {
                                        String version = listSubstitute.get(y).getUsageAversion();
                                        String aiteration = listSubstitute.get(y).getUsageAiteration();
                                        String pVersion = parentDetailsVO.getVersion();
                                        String piteration = parentDetailsVO.getIteration();
                                        if (version.equals(pVersion) == false || aiteration.equals(
                                                piteration) == false) {
                                            listSubstitute.remove(a);
                                            a--;
                                        }
                                    }
                                }


                                if (listSubstitute != null && listSubstitute.size() > 0) {
                                    AlternativeNumbers.add(childPartBomTree.getObjectNumber());
                                    List<String> aNumbers = new ArrayList<>();
                                    aNumbers.add(childPartBomTree.getObjectNumber());
                                    for (int s = 0; s < listSubstitute.size(); s++) {
                                        PartSubstituteVO partSubstituteVO = listSubstitute.get(s);
                                        String plmFSubstitutionId = null;
                                        Map<String, List<String>> baAttributeMap = partSubstituteVO.getIbaAttributeMap();
                                        if (baAttributeMap != null) {
                                            if (baAttributeMap.containsKey("替代方案编码")) {
                                                List<String> cList = baAttributeMap.get("替代方案编码");
                                                if (cList.size() > 0 && "".equals(cList.get(0)) == false) {
                                                    plmFSubstitutionId = cList.get(0);
                                                }
                                            }
                                        }
                                        Map<String, Object> fz = clone(FTreeEntity.get(x));
                                        //项次
                                        fz.put("FReplaceGroup", x + 1);
                                        FTreeEntity.get(x).put("FReplaceGroup", x + 1);

                                        //子件类型： 1 标准件， 2 返还件，3 替代件
                                        fz.put("FMATERIALTYPE", "3");


                                        fz.put("FIskeyItem", true);
                                        FTreeEntity.get(x).put("FIskeyItem", true);


                                        //替代策略： 手工替代，内部值 3
                                        fz.put("FReplacePolicy", "3");
                                        FTreeEntity.get(x).put("FReplacePolicy", "3");


                                        //替代优先级
                                        fz.put("FReplacePriority", s + 1);
                                        //FTreeEntity.get(x).put("FReplacePriority",1);


                                        //动态优先级
                                        fz.put("FMRPPriority", s + 1);


                                        Map<String, String> FSubstitutionId = new HashMap<>();
                                        FSubstitutionId.put("FNUMBER", (String) plmFSubstitutionId);
                                        //替代方案编码
                                        fz.put("FSubstitutionId", FSubstitutionId);

                                        Map<String, String> FSubstitutionId1 = new HashMap<>();
                                        FSubstitutionId1.put("FNUMBER", (String) plmFSubstitutionId);
                                        FTreeEntity.get(x).put("FSubstitutionId", FSubstitutionId1);

                                        //替代方式： 1=替代，2=取代
                                        fz.put("FReplaceType", "1");
                                        FTreeEntity.get(x).put("FReplaceType", "1");

                                        Map<String, String> tdFMATERIALIDCHILD = new HashMap<>();
                                        tdFMATERIALIDCHILD.put("FNumber",
                                                               new String(listSubstitute.get(s).getNumber()));
                                        //子项物料编码
                                        fz.put("FMATERIALIDCHILD", tdFMATERIALIDCHILD);

                                        fzList.add(fz);
                                    }
                                } else {
                                    FTreeEntity.get(x).put("FReplaceGroup", x + 1);
                                }
                                //查询全局替代件
                                List<AlternateInfoVO> listAlternates = typlmPartAlternateService.batchQueryAlternates(
                                        alternateForPartNumbers);
                                if (listAlternates != null && listAlternates.size() > 0) {
                                    AlternativeNumbers.add(childPartBomTree.getObjectNumber());

                                    if (listSubstitute.size() > 0) {
                                        continue;
                                    }
                                    List<String> aNumbers = new ArrayList<>();
                                    aNumbers.add(childPartBomTree.getObjectNumber());

                                    for (int s = 0; s < listAlternates.size(); s++) {
                                        AlternateInfoVO alternateInfoVO = listAlternates.get(s);

                                        String plmFSubstitutionId = null;
                                        Map<String, List<String>> baAttributeMap = alternateInfoVO.getIbaAttributeMap();
                                        if (baAttributeMap != null) {
                                            if (baAttributeMap.containsKey("替代方案编码")) {
                                                List<String> cList = baAttributeMap.get("替代方案编码");
                                                if (cList.size() > 0 && "".equals(cList.get(0)) == false) {
                                                    plmFSubstitutionId = cList.get(0);
                                                }
                                            }
                                        }


                                        Map<String, Object> fz = clone(FTreeEntity.get(x));
                                        //项次
                                        fz.put("FReplaceGroup", x + 1);
                                        FTreeEntity.get(x).put("FReplaceGroup", x + 1);


                                        //替代主料
                                        fz.put("FIskeyItem", true);
                                        FTreeEntity.get(x).put("FIskeyItem", true);

                                        // 子项类型
                                        fz.put("FMATERIALTYPE", "3");

                                        //替代策略： 手工替代，内部值 3
                                        fz.put("FReplacePolicy", "3");
                                        FTreeEntity.get(x).put("FReplacePolicy", "3");


                                        //替代优先级
                                        fz.put("FReplacePriority", s + 1);
                                        //FTreeEntity.get(x).put("FReplacePriority",1);

                                        //动态优先级
                                        fz.put("FMRPPriority", s + 1);


                                        Map<String, String> FSubstitutionId = new HashMap<>();
                                        FSubstitutionId.put("FNUMBER", (String) plmFSubstitutionId);
                                        //替代方案编码
                                        fz.put("FSubstitutionId", FSubstitutionId);

                                        Map<String, String> FSubstitutionId1 = new HashMap<>();
                                        FSubstitutionId1.put("FNUMBER", (String) plmFSubstitutionId);
                                        FTreeEntity.get(x).put("FSubstitutionId", FSubstitutionId1);

                                        //替代方式： 1=替代，2=取代
                                        fz.put("FReplaceType", "2");
                                        FTreeEntity.get(x).put("FReplaceType", "2");

                                        Map<String, String> tdFMATERIALIDCHILD = new HashMap<>();
                                        tdFMATERIALIDCHILD.put("FNumber", new String(
                                                listAlternates.get(s).getAlternateObjectNumber()));
                                        //子项物料编码
                                        fz.put("FMATERIALIDCHILD", tdFMATERIALIDCHILD);

                                        fzList.add(fz);
                                    }
                                } else {
                                    FTreeEntity.get(x).put("FReplaceGroup", x + 1);
                                }

                            }
                        }
                    }
                }


                //排序数据
                if (AlternativeNumbers.size() > 0) {
                    Map<Integer, List<Map<String, Object>>> pxMap = new HashMap<>();
                    if (out.containsKey("Model")) {
                        Map<String, Object> Model = (Map<String, Object>) out.get("Model");
                        if (Model.containsKey("FTreeEntity")) {
                            List<Map<String, Object>> FTreeEntity = (List<Map<String, Object>>) Model.get(
                                    "FTreeEntity");
                            List<Map<String, Object>> srcList = new ArrayList<>();
                            for (int x = 0; x < FTreeEntity.size(); x++) {
                                Integer FReplaceGroup = (Integer) FTreeEntity.get(x).get("FReplaceGroup");
                                if (FReplaceGroup != null) {
                                    if (pxMap.containsKey(FReplaceGroup)) {
                                        List<Map<String, Object>> xlist = pxMap.get(FReplaceGroup);
                                        xlist.add(FTreeEntity.get(x));
                                        for (int v = 0; v < fzList.size(); v++) {
                                            Integer fzeplaceGroup = (Integer) fzList.get(v).get("FReplaceGroup");
                                            if (fzeplaceGroup == FReplaceGroup) {
                                                xlist.add(fzList.get(v));
                                            }
                                        }
                                    } else {
                                        List<Map<String, Object>> xlist = new ArrayList<>();
                                        xlist.add(FTreeEntity.get(x));
                                        for (int v = 0; v < fzList.size(); v++) {
                                            Integer fzeplaceGroup = (Integer) fzList.get(v).get("FReplaceGroup");
                                            if (fzeplaceGroup == FReplaceGroup) {
                                                xlist.add(fzList.get(v));
                                            }

                                        }
                                        pxMap.put(FReplaceGroup, xlist);
                                    }


                                } else {
                                    srcList.add(FTreeEntity.get(x));
                                }

                            }
                            List<Map<String, Object>> stroList = new ArrayList<>();
                            for (Integer i = 0; i < FTreeEntity.size() + 1; i++) {
                                if (pxMap.containsKey(i)) {
                                    List<Map<String, Object>> xlist = pxMap.get(i);
                                    for (int v = 0; v < xlist.size(); v++) {
                                        stroList.add(xlist.get(v));
                                    }
                                }
                            }

                            for (int i = 0; i < srcList.size(); i++) {
                                stroList.add(srcList.get(i));
                            }


                            Model.put("FTreeEntity", stroList);
                        }
                    }
                }

                JSONObject resultJson = SendErpDataUtils.sendErpDataTaskWorkder(executionType, out);

                JSONObject Result = resultJson.getJSONObject("Result");
                if (Result != null) {
                    JSONObject ResponseStatus = Result.getJSONObject("ResponseStatus");
                    if (ResponseStatus.getBooleanValue("IsSuccess") == false) {
                        throw SystemErrorCodeEnum.WORK_FLOW_CONTENT_ERROR.getException(
                                ResponseStatus.get("Errors").toString());
                    } else {
                        JSONArray successEntitys = ResponseStatus.getJSONArray("SuccessEntitys");
                        if (successEntitys.size() > 0) {
                            String erpNumber = successEntitys.getJSONObject(0).getString("Id");
                            if(erpNumber!=null && "null".equals(erpNumber)==false){
                                erpNumbers.add(erpNumber);
                            }
                        }
                    }
                }
            }

            if (erpNumbers.size() == 0) {
                JSONObject httpResult = new JSONObject();
                JSONObject resultObj = new JSONObject();
                JSONObject responseStatus = new JSONObject();
                responseStatus.put("IsSuccess", true);
                responseStatus.put("msg", "数据为空");
                resultObj.put("ResponseStatus", responseStatus);
                httpResult.put("Result", resultObj);
                return httpResult;
            }

            executionType.put("code","TJ000006X");
            //构建批量提交,审核数据，发送ERP提交BOM
            JSONObject erpResult = SubmissionAndReviewHanding.submittReviewByIds(executionType, erpNumbers);
            if (erpResult.containsKey("Result")) {
                JSONObject Result = erpResult.getJSONObject("Result");
                if (Result.containsKey("ResponseStatus")) {
                    JSONObject ResponseStatus = Result.getJSONObject("ResponseStatus");
                    if (ResponseStatus.getBooleanValue("IsSuccess") == false) {
                        throw SystemErrorCodeEnum.WORK_FLOW_CONTENT_ERROR.getException(
                                ResponseStatus.get("Errors").toString());
                    }
                }
            }
            return erpResult;
        }

        return null;
    }

    public Map<String, Object> clone(Map<String, Object> srcMap) {
        Map<String, Object> descMap = new HashMap<>();
        cloneMap(descMap, srcMap);
        return descMap;
    }

    public void cloneMap(Map<String, Object> descMap, Map<String, Object> srcMap) {
        Set<Map.Entry<String, Object>> set = srcMap.entrySet();
        for (Map.Entry<String, Object> entity : set) {
            Object obj = entity.getValue();
            if (obj instanceof Map) {
                descMap.put(entity.getKey(), new HashMap<>());
                cloneMap((Map<String, Object>) descMap.get(entity.getKey()), (Map<String, Object>) obj);
            } else if (obj instanceof List) {
                List list = (List) obj;
                if (list != null) {
                    if (list.size() > 0) {
                        if (list.get(0) instanceof Map) {
                            List<Map<String, Object>> addList = new ArrayList<>();
                            Map<String, Object> addMap = new HashMap<>();
                            addList.add(addMap);
                            descMap.put(entity.getKey(), addList);
                            cloneMap(descMap, addMap);
                        } else {
                            descMap.put(entity.getKey(), entity.getValue());
                        }
                    }
                }
            } else {
                descMap.put(entity.getKey(), entity.getValue());
            }
        }
    }

    /**
     * 创建BOM分组
     * @param partDetails
     * @param executionType
     * @return
     * @throws Exception
     */
    public String createGroup(PartDetailsVO partDetails, Map<String, Object> executionType) throws Exception {
        Map<String, List<String>> attr=partDetails.getIbaAttributeMap();

        //取物料号作为分组编码，分组编码在ERP中是唯一的
        String groupNumberStr = partDetails.getNumber();
        String groupName = "";
        //电机成品、机电一体成品有图纸号
        if (attr.containsKey("图纸号") && !attr.get("图纸号").isEmpty() && !"".equals(attr.get("图纸号").get(0))) {
            List<String> attrList = attr.get("图纸号");
            groupName = String.format("%s-%s", attrList.get(0), partDetails.getName());
        }
        //变频器产品有型号，取不到图纸号就尝试取型号
        if ("".equals(groupName)) {
            if (attr.containsKey("型号") && !attr.get("型号").isEmpty() && !"".equals(attr.get("型号").get(0))) {
                List<String> attrList = attr.get("型号");
                groupName = String.format("%s-%s", attrList.get(0), partDetails.getName());
            }
        }
        //如果图纸号、型号都取不到说明数据有问题
        if ("".equals(groupName)) {
            return null;
        }
        JSONObject outMap = new JSONObject();
        outMap.put("GroupFieldKey","");
        outMap.put("GroupPkId",0);
        outMap.put("FParentId", 0);
        outMap.put("FNumber",groupNumberStr);
        outMap.put("FName", groupName);
        outMap.put("FDescription", "");

        executionType.put("uri","/K3Cloud/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.GroupSave.common.kdsvc");
        JSONObject httpResult = SendErpDataUtils.sendErpDataTaskWorkder(executionType,outMap);
        if(httpResult!=null){
            JSONObject Result=httpResult.getJSONObject("Result");
            JSONObject ResponseStatus = Result.getJSONObject("ResponseStatus");
            if(ResponseStatus.getBooleanValue("IsSuccess")){
                JSONArray SuccessEntitys=ResponseStatus.getJSONArray("SuccessEntitys");
                if(SuccessEntitys.size()>0){
                    return SuccessEntitys.getJSONObject(0).getString("Number");
                }
            }
        }
        return null;
    }
}
